package com.xique.park.controller.web;

import cn.hutool.core.date.DateUtil;
import com.xique.common.core.domain.R;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.request.web.parkInAndOut.WebParkInAndOutDetailRequest;
import com.xique.park.bean.request.web.parkInAndOut.WebParkInAndOutListRequest;
import com.xique.park.service.biz.service.IParkInOutBizService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 进出记录controller
 *
 * @author xique
 */
@Slf4j
@RestController
@RequestMapping("/web/parkInAndOut")
public class WebParkInAndOutController extends BaseController {

    @Autowired
    private IParkInOutBizService parkInOutBizService;

    /**
     * 查询进场和出场记录列表
     */
    @PostMapping("/list")
    @PreAuthorize(hasPermi = "park:parkInOut:list")
    public AjaxResult getParkInAndOutList(@Validated @RequestBody WebParkInAndOutListRequest request) {
        return parkInOutBizService.getWebParkInAndOutList(request);
    }

    /**
     * 查询某辆车进出记录详情
     */
    @PostMapping("/detail")
    @PreAuthorize(hasPermi = "park:parkInOut:query")
    public AjaxResult getParkCarInfoDetail(@Validated @RequestBody WebParkInAndOutDetailRequest request) {
        return parkInOutBizService.getWebParkInAndOutDetail(request);
    }

    /**
     * 根据项目ID删除进出记录
     */
    @PostMapping("/deleteByParkId")
    public AjaxResult deleteByParkId(@RequestBody WebParkInAndOutListRequest request) {
        Long parkId = request.getParkId();
        if (null == parkId) {
            return AjaxResult.error();
        }
        parkInOutBizService.deleteByParkId(parkId);
        return AjaxResult.success();
    }

    /**
     * 定时删除进出记录
     */
    @PostMapping("/delete")
    public R<String> delete() {
        log.info("[进出记录]-定时删除进出记录，开始时间：{}", DateUtil.now());
        parkInOutBizService.delete();
        log.info("[进出记录]-定时删除进出记录，结束时间：{}", DateUtil.now());
        return R.ok();
    }

}
